jQuery(function(){
				
	$('.chat-box-input').keyup(function(e){
		var user_id = $('#user_id').val();
		var val = $('.chat-box-input').val();								
		 if(e.keyCode==13){
			if(val != ''){ 
				$.ajax({
					url:'chat/send' ,
					type:'post',
					data: $.param({'message':val,'user_id':user_id}) ,
					success: function(){
						$('.chat-box-input').val('');
						viewChat(user_id);
					}
				});
			}
		}										   
	});		
});
/*run while click chat bar */
function oChat(id){
		jQuery('.chat-boxitem').dialog();
		viewChat(id);
	}

function viewChat(id){
	$('.chat-message').html('');
	$('.chat-message').html('<input type="hidden" id="user_id" value="'+id+'"/>');
				$.ajax({
				url:'chat/msg' ,
				type:'post',
				dataType:'json',
				data: $.param({'user_id':id}) ,
				success: function(data){
						if(data[1]!='undefined'){
							for(var i= 0 ; i<data.length; i++){
								$('.chat-message').append(data[i].message+'<div class="chat-underline"></div>');
							}
						}
					}
			});
	}


	